<template>
    <div class="app-container">
        <el-card shadow="never">
        <!-- <p style="color:#fd2f2f;">请选择美国时间，对应时间：{{ us_time | parseTime('y-m-d h:i:s 星期a') }}</p> -->
        <!-- <el-calendar :range="['2023-05-01', '2025-05-01']">
            <template
                slot="dateCell"
                slot-scope="{date, data}">
                <p :class="data.isSelected ? 'is-selected' : ''">
                {{ data.day.split('-').slice(2).join('-') }} {{ data.isSelected ? '✔️' : ''}}
                </p>
            </template>
        </el-calendar> -->

            <!-- 条件查询 -->
            <el-form v-show="showSearch" ref="queryForm" :model="queryParams" label-width="120px" @keyup.enter.native="submitSearch" @submit.native.prevent>
                <el-row>
                    <el-col :md="12" :sm="12">
                        <el-form-item label="添加时间:" prop="create_time.value">
                            <el-date-picker
                                v-model="queryParams.create_time.value"
                                type="datetimerange"
                                range-separator="至"
                                start-placeholder="开始"
                                end-placeholder="结束"
                                align="right"
                                value-format="yyyy-MM-dd HH:mm:ss"
                            >
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :md="12" :sm="12">
                        <el-form-item label="主运营:" prop="admin_id.value">
                            <SelectPage v-model="queryParams.admin_id.value" :url="'/admin/system.admin/selectPage'" show_field="nickname" query_field="nickname" :multiple="false" />
                        </el-form-item>
                    </el-col>
                    <el-col :md="12" :sm="12">
                        <el-form-item class="ele-text-right" label-width="50px">
                            <el-button type="primary" size="mini" @click="submitSearch" icon="el-icon-search" class="ele-btn-icon">搜索 </el-button>
                            <el-button @click="resetQuery" size="mini" icon="el-icon-refresh">重置</el-button>

                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            
            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                    <!-- <el-button type="primary" plain size="mini"  @click="day_change">查看花费</el-button> -->
                </el-col>
                <el-col :span="1.5">
                    <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="open" v-hasPermi="api.add">添加</el-button>
                </el-col>
                <el-col :span="1.5">
                    <el-upload
                        class="upload-demo"
                        ref="upload"
                        :action="api.upload"
                        :on-preview="handlePreview"
                        :on-remove="handleRemove"
                        :on-success="handleUploadSuccess"
                        :on-error="handleUploadError"
                        :file-list="fileList"
                        :auto-upload="false">
                        <el-button slot="trigger" size="mini" type="primary">选择文件</el-button>
                        <el-button style="margin-left: 10px;" size="mini" type="success" @click="submitUpload">上传花费</el-button>
                        <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div> -->
                    </el-upload>
                </el-col>
                <!-- <el-col :span="1.5">
                    <el-button type="warning" plain icon="el-icon-download" size="mini" v-loading="exportLoading" @click="handleExport" v-hasPermi="api.export">导出</el-button>
                </el-col> -->
                <right-toolbar :showSearch.sync="showSearch" @queryTable="initIndex" :columns="columns" printId="#quickadmin"></right-toolbar>
            </el-row>

            <!-- 列表 -->
            <qa-table
                :source="tableData"
                :columns="columns"
                :selection="true"
                :loading="loading"
                @sortChange="sortChange"
                @statusChange="statusChange"
                @selectionChange="selectionChange"
                id="quickadmin"
            >
                <template v-slot:action>
                    <el-table-column label="操作" width="240" align="left">
                        <template slot-scope="scope">
                            <el-button class="btn-mar" size="mini" type="primary" @click="handleEdit(scope.row)" v-hasPermi="api.edit">编辑</el-button>
                            <el-button class="btn-mar" size="mini" type="info" @click="handleDetail(scope.row)" v-hasPermi="api.find">详情</el-button>
                            <el-button class="btn-mar" size="mini" type="danger" @click="handleDelete(scope.row)" v-hasPermi="api.delete">删除</el-button>
                        </template>
                    </el-table-column>
                </template>
              
            </qa-table>

            <!-- 分页 -->
            <pagination :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="initIndex" />
        </el-card>

        <!-- 编辑弹窗 -->
       <el-dialog :title="!disabled ? '编辑' : '详情'" :visible="editOpen"  :before-close="beforeClose" destroy-on-close>
            <EditForm ref="editForm" :findFormData="findFormData"  :disabled="disabled" @submitForm="submitForm" :editFormParams="editFormParams" @editFormCancel="beforeClose" />
        </el-dialog>

    </div>
</template>

<script>
import { curdMixin } from '@/mixins/curdMixin'
import EditForm from './EditFormCom'
export default {
    name: 'Curd',
    mixins: [curdMixin],
    components: { EditForm },
    
    data() {
        return {
            fileList: [],
            us_time: 0,
            value: new Date(),
            // table结构
            columns: [
                // {
                //     visible: true,
                //     label: 'id',
                //     prop: 'id',
                // },
                {
                    visible: true,
                    label: '花费',
                    prop: 'cost',
                },
                {
                    visible: true,
                    label: '平台',
                    prop: 'adv_name',
                },
                {
                    visible: true,
                    label: '账号',
                    prop: 'site_title',
                },
                // {
                //     visible: true,
                //     label: 'cpc',
                //     prop: 'cpc',
                // },
                // {
                //     visible: true,
                //     label: 'click',
                //     prop: 'click',
                // },
                {
                    visible: true,
                    label: '添加人',
                    prop: 'admin_title',
                },
                {
                    visible: true,
                    label: '消耗时间(美国日期)',
                    prop: 'create_time',
                },
                {
                    visible: true,
                    label: '类型',
                    prop: 'type',
                    component: 'QuickAdminTag',
                    formatter: (prop, row) => {
                        console.log('terowst',row.type);
                        if(row.type == 0){
                            row.type = '手动'
                        }
                        if(row.type == 1){
                            row.type = 'API'
                        }
                        return row.type
                    },
                },
                // {
                //     visible: true,
                //     label: '更新时间',
                //     prop: 'update_time',
                // },

            ],
            // 接口地址
            api: {
                index: `/admin/advertising/index`,
                find: `/admin/advertising/find`,
                add: `/admin/advertising/add`,
                edit: `/admin/advertising/edit`,
                delete: `/admin/advertising/delete`,
                export: `/admin/advertising/export`,
                upload: `https://api.fan-zhou.com/admin/advertising/uploads`,
                status: `/admin/advertising/status`
            },
            editFormParams: {
            },
            pageInfo: {
                sort: 'id',
            },
            primaryKey: 'id',
            // 搜索表单是否展开
            searchExpand: false,
              //是否展示搜索
            showSearch: true,
            // 查询参数
            queryParams: {
                create_time: { value: [], op: 'range' },
                admin_id: { value: [], op: '=' },
            },

        }
    },
    created () {
        this.initIndex()
        this.now()
    },
    watch: {
        
    },
    methods: {
        day_change() {
            
            console.log('test',this.value);
            console.log('data.isSelected',this.data.isSelected);
        },
        now() {
            this.us_time = new Date().getTime() - 15 * 3600 * 1000;
            setInterval(() => {
                this.us_time = new Date().getTime() - 15 * 3600 * 1000;
            }, 1000)
        },
        // 案列：当前组件格式化方法
        testFormatter(prop) {
            return prop
        },
        
        submitUpload() {
            this.$refs.upload.submit();
        },
        handleRemove(file, fileList) {
            console.log(file, fileList);
        },
        handlePreview(file) {
            console.log(file);
        },
        
        // 上传成功回调
        handleUploadSuccess(res) {
            console.log('tesrest',res);
            if (res.code == 1) {
                this.$message.success('上传成功');
                this.initIndex();
            } else {
                this.$message({
                    type: 'error',
                    message: '上传失败'+res.msg,
                })
            }
        },
        // 上传失败
        handleUploadError() {
            this.$message({
                type: 'error',
                message: '上传失败',
            })
        },
    }
}
</script>
<style lang="scss">
.btn-mar {
    margin: 5px !important;
}
.is-selected {
    color: #1989FA;
}
</style>